From 3504f494736af12b2b9270527df044aacea19236 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 14 Mar 2014 06:28:49 -0400 Subject: [PATCH] Show dialog titles We want to present a clean, rounded top when there is nothing else to show, but many dialogs in applications rely on showing information in their title, so add a label and show the title when it is not empty. --- gtk/gtkdialog.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/gtk/gtkdialog.c b/gtk/gtkdialog.c index 37d9bf0bce..3b54c46b00 100644 --- a/gtk/gtkdialog.c +++ b/gtk/gtkdialog.c @@ -271,6 +271,18 @@ add_cb (GtkContainer *container, gtk_widget_show (GTK_WIDGET (container)); } +static void +update_title (GObject *dialog, + GParamSpec *pspec, + GtkWidget *label) +{ + const gchar *title; + + title = gtk_window_get_title (GTK_WINDOW (dialog)); + gtk_label_set_label (GTK_LABEL (label), title); + gtk_widget_set_visible (label, title && title[0]); +} + static void apply_use_header_bar (GtkDialog *dialog) { @@ -284,9 +296,15 @@ apply_use_header_bar (GtkDialog *dialog) if (gtk_window_get_type_hint (GTK_WINDOW (dialog)) == GDK_WINDOW_TYPE_HINT_DIALOG) { + GtkWidget *label; + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_widget_show (box); gtk_widget_set_size_request (box, -1, 16); + label = gtk_label_new (""); + gtk_style_context_add_class (gtk_widget_get_style_context (label), "title"); + gtk_box_set_center_widget (GTK_BOX (box), label); + g_signal_connect (dialog, "notify::title", G_CALLBACK (update_title), label); } gtk_window_set_titlebar (GTK_WINDOW (dialog), box); -- 2.30.2